package com.apes.fn.ssm.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.masterdata.product.model.Brand;
import com.apes.scm.masterdata.product.model.Category;
import com.apes.scm.masterdata.product.model.Product;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName : FittingMessage
 * @Description : 组合配件信息
 * @Author : WSl
 * @Date: 2022-6-21 10:37
 */

@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = FittingMessage.CONST_TABLE_NAME)
public class FittingMessage extends BaseModel {
public final static String CONST_TABLE_NAME = "mas_fitting_message";

    @Id
    @Column(name = "id", length = 10)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "组合配件信息")
    @Comment("编码")
    private String id;

    @Column(name = "name", nullable = false, length = 20)
    @Comment("组合配件名称")
    private String name;

    @ManyToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE}, fetch = FetchType.LAZY)
    @JoinTable(name = "mas_sub_category",
            joinColumns = {@JoinColumn(name = "fitting_message_id", referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "category_id", referencedColumnName = "id")}
    )
    @Comment("配件编码")
    private List<Category> categoryList = new ArrayList<>();

    @Column(name = "valid", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("配件测算标记")
    private boolean valid = false;

    @Column(name = "product_state", length = 100)
    @Comment("商品状态")
    private String product;

    @Transient
    private List<Brand> brand;//品牌

    public FittingMessage() {
    }

    public FittingMessage(String id) {
        this.id = id;
    }
}
